package cn.dylan.pet.controller;

import cn.dylan.basic.annotation.PreAuthorize;
import cn.dylan.basic.util.JsonResult;
import cn.dylan.basic.util.LogininfoContext;
import cn.dylan.basic.util.PageList;

import cn.dylan.pet.domain.PetDetail;
import cn.dylan.pet.domain.SearchMasterMsgAuditLog;
import cn.dylan.pet.query.PetQuery;
import cn.dylan.pet.query.SearchMasterMsgAuditLogQuery;
import cn.dylan.pet.service.ISearchMasterMsgAuditLogService;
import cn.dylan.user.domain.Logininfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/searchMasterMsgAuditLog")
public class SearchMasterMsgAuditLogController {

    @Autowired
    private ISearchMasterMsgAuditLogService searchMasterMsgAuditLogService;


    /**
     *
     * @return
     */
    @ApiOperation(value = "查询所有" )
    @GetMapping
    public List<SearchMasterMsgAuditLog> loadAll(HttpServletRequest request){
        Logininfo logininfo = LogininfoContext.getLogininfo(request);
        return searchMasterMsgAuditLogService.loadAll();
    }

    /**
     * GetMapping 请求
     * @requstMapping(value = "", method = "get")
     * @param id
     * @return
     */
    @ApiOperation(value = "通过ID查询" )
    @GetMapping("/{id}")
    public SearchMasterMsgAuditLog loadById(@PathVariable("id") Long id){
        return searchMasterMsgAuditLogService.LoadById(id);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable("id") Long id){
        System.out.println(id);
        try {
            searchMasterMsgAuditLogService.delete(id);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("操作失败");
        }
    }

    /**
     * 修改和添加
     * @param searchMasterMsgAuditLog
     * @return
     */
    @PostMapping
    @ApiOperation(value = "修改或者添加" )
    public JsonResult updateOrAdd(@RequestBody SearchMasterMsgAuditLog searchMasterMsgAuditLog){
        try {
            if(searchMasterMsgAuditLog.getId()==null){
                //添加操作
                searchMasterMsgAuditLogService.save(searchMasterMsgAuditLog);
            }else {
                searchMasterMsgAuditLogService.update(searchMasterMsgAuditLog);
            }
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("操作失败");
        }
    }

    /**
     * 分页查询
     * @param query
     * @return
     */
    @PutMapping
    @ApiOperation(value = "分页查询" )
    public PageList<SearchMasterMsgAuditLog> QueryPage(@RequestBody SearchMasterMsgAuditLogQuery query){

        try {
            return searchMasterMsgAuditLogService.queryPage(query);
        } catch (Exception e) {
            e.printStackTrace();
            return new PageList();
        }
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除部门" )
    @PatchMapping
    public JsonResult patchDelete(@RequestBody List<Long> ids){
        try {
            searchMasterMsgAuditLogService.patchDelete(ids);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("操作失败");
        }
    }


}
